package com.ljb.designpatterns.singleton;

/**
 * 懒汉式单例,double check,volatile关键字
 * Created by ljb on 2018/6/25.
 */
public class SingleA {
    /**
     * volatile关键字,禁止指令重排,
     */
    static volatile SingleA instance;

    private SingleA() {
    }

    public static SingleA getInstance() {
        if (instance == null) {
            synchronized (SingleA.class) {
                if (instance == null) {
                    instance = new SingleA();
                }
            }
        }
        return instance;
    }
}
